<?php $this->load->view('common/head');?>

<?php $this->load->view('common/header');?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar');?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs');?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set');?>
			
						<div class="row">
							<div class="col-xs-12">
								<form accept-charset="UTF-8" id="new_add" action="<?php echo site_url(X_URL.'orders/pay_order_do');?>" class="form-horizontal" role="form" method="post" novalidate="novalidate" id="form1">
								<?php echo csrf_hidden();?>
                                    <input type="hidden" id="order_no_hidden" name="order_no_hidden" value="<?php echo $order['order_no'];?>">
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label no-padding-right" for="is_rewrite"> 订单编号 </label>
                                        <div class="col-sm-9">
                                            <div class="radio">
                                                <label> <?php echo $order['order_no'];?>
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label no-padding-right" for="is_rewrite"> 订单商品总价 </label>
                                        <div class="col-sm-9">
                                            <div class="radio">
                                                <label> ¥
                                                    <span class="good_price" price="<?php echo $order['good_price'];?>"><?php echo $order['good_price'];?></span>
                                                </label>
                                            </div>
                                        </div>
                                    </div>
									<div class="space-4"></div>
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="is_rewrite"> 是否开票 </label>
										<div class="col-sm-9">
											<div class="radio">
												<label class="col-md-2 col-xs-6 col-sm-4">
													<input name="is_kaipiao" type="radio" class="ace" value="1">
													<span class="lbl"> 是（10%税点）</span>
												</label>
												<label class="col-md-2 col-xs-6 col-sm-4">
													<input name="is_kaipiao" type="radio" class="ace" value="2" checked>
													<span class="lbl"> 否</span>
												</label>
											<span class="help-block col-sm-reset inline hidden-480">请选择是否开票</span>
											</div>
										</div>
									</div>	
									<div class="space-4"></div>
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="voucher_close"> 是否送货 </label>
										<div class="col-sm-9">
											<div class="radio">
												<label class="col-md-2 col-xs-6 col-sm-4">
													<input name="is_songhuo" type="radio" class="ace" value="1" >
													<span class="lbl"> 是</span>
												</label>
												<label class="col-md-2 col-xs-6 col-sm-4">
													<input name="is_songhuo" type="radio" class="ace" value="2" checked>
													<span class="lbl"> 否</span>
												</label>
											<span class="help-block col-sm-reset inline hidden-480">请选择是否送货</span>
											</div>
										</div>
									</div>
                                    <input type="hidden" id="songhuo_fee_hidden" name="songhuo_fee" value="<?php echo $songhuo_fee;?>">
                                    <input type="hidden" id="kaipiao_fee_hidden" name="kaipiao_fee" value="<?php echo $kaipiao_fee;?>">
                                    <input type="hidden" id="service_fee_hidden" name="service_fee" value="<?php echo $service_fee;?>">
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label no-padding-right" for="is_rewrite"> 订单总价 </label>
                                        <div class="col-sm-9">
                                            <div class="radio">
                                                <label class="col-md-2 col-xs-8 col-sm-4"> ¥
                                                    <span class="order_price"><?php echo $order_price;?></span>
                                                    <input type="hidden" id="order_price_hidden" name="order_price" value="<?php echo $order_price;?>">
                                                </label>
                                                <span class="help-block col-sm-reset inline hidden-480" id="order_price_tips">(
                                                    <b id="service_fee_tips">包含2%的服务费</b>
                                                    <b id="kaipiao_fee_tips" style="display: none">,10%的开票费</b>
                                                    <b id="songhuo_fee_tips" style="display: none">,¥：<?php echo $songhuo_fee;?>的送货费</b>
                                                    )
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label no-padding-right" for="voucher_close"> 支付方式 </label>
                                        <div class="col-sm-9">
                                            <div class="radio">
                                                <label class="col-md-2 col-xs-6 col-sm-4">
                                                    <input name="pay_type" type="radio" class="ace" value="1" checked>
                                                    <span class="lbl"> 线下支付</span>
                                                </label>
                                                <label class="col-md-2 col-xs-6 col-sm-4">
                                                    <input name="pay_type" type="radio" class="ace" value="2">
                                                    <span class="lbl"> 销售贷支付( ¥<span id="sale_money"><?php echo $member['user_money_real'];?></span>)</span>
                                                </label>
                                                <span class="help-block col-sm-reset inline hidden-480">请选择支付方式</span>
                                            </div>
                                        </div>
                                    </div>
                                    <?php if($dress){ ?>
                                    <?php foreach ($dress as $key => $val) { ?>
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label no-padding-right" for="voucher_close"> <?php if($key == 0){?>收货地址<?php } ?> </label>
                                        <div class="col-sm-9">
                                            <div class="radio">
                                                <label class="col-md-9 col-xs-9 col-sm-9">
                                                    <input name="dress_id" type="radio" class="ace" value="<?php echo $val['dress_id'];?>" <?php if($val['dress_type'] == 1){?>checked<?php } ?> >
                                                    <span class="lbl">
                                                        <?php echo $val['dress_uname'];?>&nbsp;&nbsp;&nbsp;
                                                        <?php echo $val['dress_utel'];?>&nbsp;&nbsp;&nbsp;
                                                        <?php echo $val['dress_city'].$val['dress_udress'];?>
                                                    </span>
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <?php } ?>
                                    <?php }?>
                                    <div class="form-group add_address">
                                        <label class="col-sm-3 control-label no-padding-right" for="voucher_close"> </label>
                                        <div class="col-sm-9">
                                            <div class="radio">
                                                <label class="col-md-9 col-xs-9 col-sm-9">
                                                    <span class="lbl">
                                                        <a href="javascript:;" id="add_addr">添加地址</a>
                                                    </span>
                                                </label>
                                            </div>
                                        </div>
                                    </div>

									<div class="clearfix form-actions">
										<div class="col-md-offset-3 col-md-9">
											<button class="btn btn-info" type="submit" id="subForm1">
												<i class="ace-icon fa fa-check bigger-110"></i>
												确认支付
											</button>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div><!-- /.main-content -->

    <?php $this->load->view('common/footer');?>

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div><!-- /.main-container -->
<?php $this->load->view('common/footerjs');?>
<?php echo admin_js_url('custom');?>
<script type="text/javascript">
    $("#add_addr").click(function () {
        $.popPage({
                url: baseurl+"index.php/manage/orders/tanchuang",
                title: "添加地址",
                data:{}
            },
            {
                height:$(window).height()
            });
    });
</script>
<script>
    var songhuo_fee = $("#songhuo_fee_hidden").val();
    var kaipiao_fee = $("#kaipiao_fee_hidden").val();
    $('input:radio[name="is_kaipiao"]').click(function(){
        var is_kaipiao=$('input:radio[name="is_kaipiao"]:checked').val();
        var order_price = $("#order_price_hidden").val();
        if(is_kaipiao == 1){
            var t_price = sum_price(order_price,kaipiao_fee);
            $("#kaipiao_fee_tips").show();
        }else{
            var t_price = sum_price_i(order_price,kaipiao_fee);
            $("#kaipiao_fee_tips").hide();
        }
        $('.order_price').html(parseFloat(t_price));
        $('#order_price_hidden').val(parseFloat(t_price));
    });
    // 获取送货费
    $('input:radio[name="is_songhuo"]').click(function () {
        var is_songhuo=$('input:radio[name="is_songhuo"]:checked').val();
        var order_price = $("#order_price_hidden").val();
        if(is_songhuo == 1){
            var t_price = sum_price(order_price,songhuo_fee);
            $("#songhuo_fee_tips").show();
        }else{
            var t_price = sum_price_i(order_price,songhuo_fee);
            $("#songhuo_fee_tips").hide();
        }
        $('.order_price').html(parseFloat(t_price));
        $('#order_price_hidden').val(parseFloat(t_price));
    });
    $("#subForm1").click(function () {

        var order_price = $("#order_price_hidden").val();
        var sale_money = $("#sale_money").html();
        var pay_type=$('input:radio[name="pay_type"]:checked').val();
        if(pay_type == 2){
            if (order_price*1000 > sale_money*1000) {
                bootbox.dialog({
                    title: '提示：',
                    message: "您的销售贷不足以支付此订单。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
        }
        $("#from1").submit();
    });

    function sum_price(a, b) {
        var c, d, e;
        try {
            c = a.toString().split(".")[1].length;
        } catch (f) {
            c = 0;
        }
        try {
            d = b.toString().split(".")[1].length;
        } catch (f) {
            d = 0;
        }
        return e = Math.pow(10, Math.max(c, d)), (mul(a, e) + mul(b, e)) / e;
    }
    function sum_price_i(a, b) {
        var c, d, e;
        try {
            c = a.toString().split(".")[1].length;
        } catch (f) {
            c = 0;
        }
        try {
            d = b.toString().split(".")[1].length;
        } catch (f) {
            d = 0;
        }
        return e = Math.pow(10, Math.max(c, d)), (mul(a, e) - mul(b, e)) / e;
    }
    function mul(a, b) {
        var c = 0,
            d = a.toString(),
            e = b.toString();
        try {
            c += d.split(".")[1].length;
        } catch (f) {}
        try {
            c += e.split(".")[1].length;
        } catch (f) {}
        return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
    }
</script>
</body>
</html>